﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using MVP;
using System.Globalization;

namespace WinForms
{
    public partial class LaporanTriwulan : UserControl, ILaporanTriwulanView
    {
        LaporanTriwulanPresenter _presenter;
        public LaporanTriwulanPresenter GetPresenter()
        {
            return _presenter;
        }
        public LaporanTriwulan()
        {
            _presenter = new LaporanTriwulanPresenter(this);
            InitializeComponent();
        }

        public LaporanTriwulan(string triwulan, string tahun)
            : this()
        {
            Triwulan = triwulan;
            Tahun = tahun;
        }

        #region ILaporanTriwulanView Members

        public DataSet LppbopDataSet
        {
            set
            {
                BindingSource bindingSource = new BindingSource(this.components);
                bindingSource.DataSource = value;
                bindingSource.DataMember = "LaporanTriwulan";
                lapTriwulanDataGridView.DataSource = bindingSource;
                lapTriwulanBindingNavigator.BindingSource = bindingSource;
            }
            get
            {
                return (DataSet)((BindingSource)lapTriwulanDataGridView.DataSource).DataSource;
            }
        }

        public string Tahun
        { get; set; }

        public string Triwulan
        { get; set; }

        public void SendMessageInfo(string strMessage)
        {
            MessageBox.Show(strMessage, "Information Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        public event EventHandler Save;

        public event EventHandler Initialize;

        #endregion

        private void LaporanTriwulan_Load(object sender, EventArgs e)
        {
            Initialize(sender, e);
            updateToolStripButton.Enabled = false;
            periodeToolStripLabel.Text = String.Format("LAPORAN TRIWULAN {0} {1}", Triwulan, Tahun);
            lapTriwulanDataGridView.AllowUserToAddRows = false;

            lapTriwulanDataGridView.Columns["Id"].Visible = false;
            lapTriwulanDataGridView.Columns["Triwulan"].Visible = false;
            lapTriwulanDataGridView.Columns["Tahun"].Visible = false;

            lapTriwulanDataGridView.Columns[3].HeaderText = "No.";
            lapTriwulanDataGridView.Columns[3].Width = 30;

            lapTriwulanDataGridView.Columns[4].Width = 300;

            lapTriwulanDataGridView.Columns[5].HeaderText = "Prosentase Anggaran";
            lapTriwulanDataGridView.Columns[5].ReadOnly = true;
            lapTriwulanDataGridView.Columns[5].Width = 70;
            lapTriwulanDataGridView.Columns[5].DefaultCellStyle.Format = "p";

            lapTriwulanDataGridView.Columns[6].HeaderText = "Jumlah Anggaran";
            lapTriwulanDataGridView.Columns[6].ReadOnly = true;
            lapTriwulanDataGridView.Columns[6].Width = 100;
            lapTriwulanDataGridView.Columns[6].DefaultCellStyle.FormatProvider = CultureInfo.GetCultureInfo("id-ID");
            lapTriwulanDataGridView.Columns[6].DefaultCellStyle.Format = "c";

            lapTriwulanDataGridView.Columns[7].HeaderText = "Jumlah Realisasi";
            lapTriwulanDataGridView.Columns[7].ReadOnly = true;
            lapTriwulanDataGridView.Columns[7].Width = 100;
            lapTriwulanDataGridView.Columns[7].DefaultCellStyle.FormatProvider = CultureInfo.GetCultureInfo("id-ID");
            lapTriwulanDataGridView.Columns[7].DefaultCellStyle.Format = "c";

            lapTriwulanDataGridView.Columns[8].HeaderText = "Prosentase Pajak";
            lapTriwulanDataGridView.Columns[8].ReadOnly = true;
            lapTriwulanDataGridView.Columns[8].Width = 70;
            lapTriwulanDataGridView.Columns[8].DefaultCellStyle.Format = "p";

            lapTriwulanDataGridView.Columns[9].HeaderText = "Pajak Yang Diterima";
            lapTriwulanDataGridView.Columns[9].ReadOnly = true;
            lapTriwulanDataGridView.Columns[9].Width = 100;
            lapTriwulanDataGridView.Columns[9].DefaultCellStyle.FormatProvider = CultureInfo.GetCultureInfo("id-ID");
            lapTriwulanDataGridView.Columns[9].DefaultCellStyle.Format = "c";

            lapTriwulanDataGridView.Columns[10].HeaderText = "Pajak Yang Disetorkan";
            lapTriwulanDataGridView.Columns[10].ReadOnly = true;
            lapTriwulanDataGridView.Columns[10].Width = 100;
            lapTriwulanDataGridView.Columns[10].DefaultCellStyle.FormatProvider = CultureInfo.GetCultureInfo("id-ID");
            lapTriwulanDataGridView.Columns[10].DefaultCellStyle.Format = "c";

            lapTriwulanDataGridView.Columns[11].HeaderText = "Sisa Dana";
            lapTriwulanDataGridView.Columns[11].ReadOnly = true;
            lapTriwulanDataGridView.Columns[11].Width = 100;
            lapTriwulanDataGridView.Columns[11].DefaultCellStyle.FormatProvider = CultureInfo.GetCultureInfo("id-ID");
            lapTriwulanDataGridView.Columns[11].DefaultCellStyle.Format = "c";

            lapTriwulanDataGridView.Columns[12].HeaderText = "Keterangan";
        }

        private void updateToolStripButton_Click(object sender, EventArgs e)
        {
            ((BindingSource)lapTriwulanDataGridView.DataSource).EndEdit();
            Save(sender, e);
            updateToolStripButton.Enabled = false;
        }

        private void lapTriwulanDataGridView_CurrentCellDirtyStateChanged(object sender, EventArgs e)
        {
            updateToolStripButton.Enabled = true;
        }

        private void lapTriwulanDataGridView_Paint(object sender, PaintEventArgs e)
        {

        }
    }
}
